/**
 * 医生详情
 */
$(function() {
	////初始化列表页面
	$(window).on("load", queryMyDoctorList);
	//跳转详情页【列表】
	$(".showDataResult").on("click", ".diseaseCls", function() {
		enterDetail($(this).attr("v"));
	});
	
	/**
	 * 调用Model 检索接口
	 * @param {Object} _pageNo
	 * @param {Object} _pageSize
	 */
	function loadPageData() {
		var doctorObj={};
		var params = {
			"patientid":USERID	
		};
		userCenterModule.myAdavate(params, function(callBack) {
			var a = [];
			for(var i=0,leng=callBack.length;i<leng;i++){
				a.push(callBack[i].doctor);
			}
			doctorObj.list= a;
		});
		return doctorObj;
	}
	//页面初始化及检索
	function queryMyDoctorList() {
		var returnData = loadPageData();
		console.log(returnData);
		utilModule.renderHtml("#doctorDataBody", "doctorDataDiv", returnData);
	}
	
	//点击问医生跳转
	$(".showDataResult").on("tap",".ask-doctor",function(event){
		event.stopPropagation();
		var imopen = $(this).attr("z");
	 	if(imopen==0){
	 		mui.alert("该医生暂未开通图文咨询服务");
	 	}else{
			var doctorid=$(this).attr("v");
			var imprice=$(this).attr("p");
			var detail=$(this).attr("detail");
			var  consultOrder={};
			consultOrder.doctorid=doctorid;
			consultOrder.payAmount=imprice;
			consultOrder.orderDetail=detail;
			consultOrder.orderType=1;
			
			var result=checkUnfinishedOrder(USERID,doctorid);
			if(result==true){
			  var orderKey="doctor_index";
			   sessionStorage.setItem(orderKey,JSON.stringify(consultOrder));
				location.replace("ask-doctor.html?doctorid="+doctorid);
			}else{
				return false;
			}
		}
	});
	
	//跳转详情
	function enterDetail(doctorid) {
		location.href = "doctor-details.html?doctorid=" + doctorid;
	}
	
	document.getElementById('index').addEventListener('tap',function(){
		mui.openWindow({
			url:'../../index.html',
    		id:'index',
		});
	});
	document.getElementById('message').addEventListener('tap',function(){
		mui.openWindow({
			url:'../../html/inquiry/message-list.html',
    		id:'message',
		});
	});
	document.getElementById('article').addEventListener('tap',function(){
		mui.openWindow({
			url:'../../html/article/article-list.html',
    		id:'article',
		});
	});
	document.getElementById('userCenter').addEventListener('tap',function(){
		mui.openWindow({
			url:'../../html/userCenter/user-center.html',
    		id:'userCenter',
		});
	});
});